#include <iostream>
#include "contacts.pb.h"
using namespace std;

int main(){
    string person_str;

    // 对一个联系人信息使用 PB 进行序列化
    {
        // Create a Person object and set its fields
        contacts::Person person;
        person.set_name("Island");
        person.set_age(18);
        if(!person.SerializeToString(&person_str)){
            cerr << "Failed to serialize person." << endl;
            return 1;
        }
        cout << "Serialized person: " << person_str << endl;
    }

    // 对序列化的内容使用 PB 进行反序列化
    {
        contacts::Person person;
        if(!person.ParseFromString(person_str)){
            cerr << "Failed to parse person." << endl;
            return 1;
        }
        cout << "Parsed person: " << person.name() << ", age: " << person.age() << endl;
    }
    return 0;
}